mod checked {
    #[derive(Debug)]
    enum MathError {
        DivisionByZero,
        NegativeLogarithm,
        NegativeSquareRoot,
    }
    type MathResult<T> = Result<T, MathError>;

    fn divide(x: f64, y: f64) -> MathResult<f64> {
        if y == 0.0 {
            Err(MathError::DivisionByZero)
        } else {
            Ok(x / y)
        }
    }
    fn sqrt(x: f64) -> MathResult<f64> {
        if x < 0.0 {
            Err(MathError::NegativeSquareRoot)
        } else {
            Ok(x.sqrt())
        }
    }
    fn ln(x: f64) -> MathResult<f64> {
        if x <= 0.0 {
            Err(MathError::NegativeLogarithm)
        } else {
            Ok(x.ln())
        }
    }
    // 中间函数
    fn op_(x: f64, y: f64) -> MathResult<f64> {
        let ratio = divide(x, y)?;
        let ln = ln(ratio)?;
        sqrt(ln)
    }

   pub fn op(x: f64, y: f64) {
        match op_(x, y) {
            Err(why) => panic!("{}", match why {
                MathError::NegativeLogarithm => "logarithm of negative number",
                MathError::NegativeSquareRoot => "square root of negative number",
                MathError::DivisionByZero => "division by zero",
            }),
            Ok(v) => println!("{}", v),
        }
    }
}
use crate::checked as chk;
fn main() {
//     这会失败吗？
    chk::op(1.0, 0.0);

}
